package com.example.xunai.dto.response.ai;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BatchChatResponse {
    private String batchId;
    private Integer totalRequests;
    private Integer successCount;
    private Integer failureCount;
    private List<ChatResponse> responses;
    private Long processingTime;
    private String status; // "processing", "completed", "failed"

    public static BatchChatResponse processing(String batchId, Integer totalRequests) {
        return BatchChatResponse.builder()
                .batchId(batchId)
                .totalRequests(totalRequests)
                .successCount(0)
                .failureCount(0)
                .status("processing")
                .build();
    }

    public static BatchChatResponse completed(String batchId, Integer totalRequests,
                                              Integer successCount, Integer failureCount,
                                              List<ChatResponse> responses, Long processingTime) {
        return BatchChatResponse.builder()
                .batchId(batchId)
                .totalRequests(totalRequests)
                .successCount(successCount)
                .failureCount(failureCount)
                .responses(responses)
                .processingTime(processingTime)
                .status("completed")
                .build();
    }

    public static BatchChatResponse failed(String batchId, String error) {
        return BatchChatResponse.builder()
                .batchId(batchId)
                .status("failed")
                .build();
    }

    public double getSuccessRate() {
        if (totalRequests == null || totalRequests == 0) return 0.0;
        return (double) successCount / totalRequests * 100;
    }
}